package com.smart.tool.transaction;

/**
 * @Author gao.gwq
 * @Version Action.java, v 0.1 2024年01月25日 15:31 gao.gwq
 * @Description: TODO
 */
@FunctionalInterface
public interface ActionWithOutResult extends BaseAction{


    /**
     * 事务执行
     *
     * @return
     */
    void doAction(TransactionContext transactionContext);

    /**
     * 异常处理
     *
     * 默认是抛出
     * 抛出处理 如果是运行时异常直接进行抛出，如果是其他的异常 会包装成运行时异常 进行抛出，
     *
     * 2. 如果需要自己进行处理，需要重写processError
     * * @example
     *  TranscationUtils.executeWithOutResult(new ActionWithOutResult () {
     *             @Override
     *             public Object doAction(TranscationContext transcationContext) {
     *             }
     *             @Override
     *             public Object processError(TranscationContext transcationContext,Throwable throwable) {
     *                  throwable.printStackTrace();
     *                   System.out.println("--事务异常--");
     *                   if(throwable instanceof RuntimeException){
     *                   throw (RuntimeException)throwable;
     *                   }
     *                   throw new RuntimeException(throwable);
     *             }
     *         });
     *     }
     *
     * @param throwable
     */
   default void processError(TransactionContext transactionContext,Throwable throwable){
       if (throwable instanceof RuntimeException){
           throw (RuntimeException)throwable;
       }
       throw new RuntimeException(throwable);
   };


}
